package com.example.lvsuo.controller.cxg;

//我的待办

import com.example.lvsuo.entity.cxg.vo.FlowDataLine;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.cxg.MyThingService;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("mythings")
public class MyThingController {

    @Autowired
    MyThingService myThingService;


    @GetMapping("/{uid}")
    public Result getMyDaiBan(@PathVariable int uid){
//        通过用户id查询角色id
        String rid = myThingService.getRid(uid);
//      通过角色ID查询节点id
        String jiedianId = myThingService.getjiedianId(rid);
//        System.out.println("节点ID==>"+jiedianId);
//        查询当前节点的待办
        List<Map<String,Object>> maps = myThingService.getMyDaiBan(jiedianId);


        return Result.back("ok","20000",maps);
    }





    @PutMapping(params={"OperationType=TongGuo"})
    public Result putFlowTongGuo(@RequestBody Map<String,Object> map){//节点审批通过处理

//        System.out.println("流程通过处理");
        Map rowData = (Map) map.get("rowData");//真正存数据的

//        System.out.println("map==>"+map);
//        查询当前流程 当前下一个审批人
        FlowDataLine nodeID = myThingService.getNextId(rowData);
//        System.out.println("下一个审批人ID==>"+nodeID);



        nodeID.setFdId(rowData.get("fd_id").toString());

        //把下一个审批人变成当前审批人
        if(StringUtil.isNullOrEmpty(nodeID.getLineNext())){//最后一个审批人
            myThingService.endPutJieDian(nodeID);// 修改流程表的状态审批人
//            查询操作表审批状态的字段名
            String approval_col = myThingService.getApprovalCol(rowData);
            rowData.put("approval_col",approval_col);
            myThingService.TableFLowApproveStatus(rowData);//修改操作表的审批状态

        }else {
            myThingService.putJieDian(nodeID);
        }

        return Result.back("ok","20000");
    }





    @PutMapping(params={"OperationType=bohiu"})//审批驳回进入
    public Result putBoHiu(@RequestBody Map<String,Object> map){//节点审批通过处理

//        System.out.println("流程驳回处理");

        Map rowData = (Map) map.get("rowData");

//        System.out.println("rowData==>"+rowData);


        myThingService.FlowBoHiu(rowData);// 修改流程表的状态审批人
//            查询操作表审批状态的字段名
        String approval_col = myThingService.getApprovalCol(rowData);
        rowData.put("approval_col",approval_col);
//        System.out.println("approval_col==>"+approval_col);
        myThingService.TableFLowBoHiuApproveStatus(rowData);//修改操作表的审批状态


        return Result.back("ok","20000");
    }


}
